#ifndef OBJFILELOADER_HPP_
# define OBJFILELOADER_HPP_

# include <list>
# include <map>
# include <vector>
# include <fstream>
# include "Vec.hpp"
# include "Mat.hpp"
# include "ALoader.hpp"

class ObjFileLoader: public ALoader
{
public:
	ObjFileLoader(void);
	~ObjFileLoader(void);

	void		load(std::string const& modelFile, const bool calcNormal) throw (std::exception);
	bool		isModelLoaded() const;

	void		readContent(std::ifstream& file);
	void		buildVertexArray(const bool calcNormal);
	void		calcNormal(const int itFace);

	unsigned int		getNbVertices() const;
	VertexAttributes*	getVertices(void);


	void				saveToFile(std::string const& outFile);

private:
	bool				_isLoaded;
	unsigned int		_nbVertices;
	VertexAttributes*	_vertices;

	// Parsing stuff
    typedef void (ObjFileLoader::*memberPointerLineParser)(std::string const& line);

	std::map<std::string, memberPointerLineParser>		_lineParser;

	std::string			getKeyword(std::string line);

	void				parseLineVertex(std::string const& line) throw (std::exception);
	std::list<Vec3f>	_readedVertex;
	void				parseLineTexture(std::string const& line) throw (std::exception);
	std::list<Vec3f>	_readedTexture;
	void				parseLineNormal(std::string const& line) throw (std::exception);
	std::list<Vec3f>	_readedNormal;
	void				parseLineFace(std::string const& line) throw (std::exception);
	std::list<Mat3i>	_readedFaces;
};

#endif // !OBJFILELOADER_HPP_
